﻿@model CompanyManagementDLL.MetaData.UserMetaData

@{
    ViewBag.Title = "Edit Profile";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<div class="row">
    <div class="col-md-9">
        <div class="box box-primary">
            <div class="box-header">
                <h3 class="box-title">Edit Profile</h3>
            </div>
            <form method="post">
                @Html.HiddenFor(model => model.UserID)
                <div class="box-body">
                    @if (TempData["Success"] != null)
                    {
                        <div class="alert alert-success alert-dismissable">
                            <i class="fa fa-check"></i>
                            <button aria-hidden="true" data-dismiss="alert" class="close" type="button">×</button>
                            <b>Success!</b> @TempData["Success"]

                        </div>
                    }
                    <div class="alert alert-success alert-dismissable" id="alert" style="display: none">
                        <i class="fa fa-check"></i>
                        <button aria-hidden="true" data-dismiss="alert" class="close" type="button">×</button>
                        <b>Success!</b> Profile Picture Update Successfully.
                   
                    </div>
                    <div class="row">
                        <div class="col-md-6">
                            <div style="color: red">
                                <b>@Html.ValidationSummary()</b>
                            </div>
                            <div class="form-group">
                                <label>User Name</label>
                                @Html.TextBoxFor(model => model.UserName, new { @class = "form-control", @placeholder = "Enter User Name" })
                            </div>
                            @Html.HiddenFor(model => model.Password)
                            @Html.HiddenFor(model => model.ConfirmPassword)
                            <div class="form-group">
                                <label>FullName</label>
                                @Html.TextBoxFor(model => model.FullName, new { @class = "form-control", @placeholder = "Enter FullName" })
                            </div>
                            <div class="form-group">
                                <label>Email Address</label>
                                @Html.TextBoxFor(model => model.EmailID, new { @class = "form-control", @placeholder = "Enter Email Address", type = "email" })
                            </div>
                            <div class="form-group">
                                <label>PhoneNumber</label>
                                @Html.TextBoxFor(model => model.PhoneNumber, new { @class = "form-control", @placeholder = "Enter PhoneNumber" })
                            </div>
                            <div class="form-group">
                                <label>Address</label>
                                @Html.TextAreaFor(model => model.Address, new { @class = "form-control", @placeholder = "Enter Address" })
                            </div>
                            @Html.HiddenFor(u => u.RoleID)
                            @Html.HiddenFor(u => u.IsActive)
                            @Html.HiddenFor(u => u.LastLoginDate)
                        </div>
                        <div class="col-md-3">
                            <div class="form-group">
                                <label>Update Profile Picture</label>
                                <input type="file" id="fileupload" />
                                @if (string.IsNullOrEmpty(Model.ProfilePicPath))
                                {
                                    <img alt="User Image" id="userimg" src="../img/avatar3.png">
                                }
                                else
                                {
                                    <img alt="User Image" id="userimg"  src="@Url.Content("~/ProfilePics/" + Model.ProfilePicPath)" />
                                }
                            </div>
                        </div>
                    </div>
                </div>
                <div class="box-footer">
                    <button class="btn btn-primary" type="submit">Submit</button>
                </div>
            </form>
        </div>
    </div>
</div>

<script>
    $("#pagetitle").html("Edit Profile");

    $('#fileupload').on('change', function (e) {
        var files = e.target.files;
        var filename = $(this).val();
        var data = new FormData();
        for (var i = 0; i < files.length; i++) {
            if (window.FormData != undefined) {
                data.append("file" + 1, files[i]);
                var request = new XMLHttpRequest();
                request.open("POST", "/Profile/UploadProfilePic");
                request.send(data);
            }
        }
        $("#userimg").attr("src", "/ProfilePics/" + filename);
        $("#smalluserimg").attr("src", "/ProfilePics/" + filename);
        $("#biguserimg").attr("src", "/ProfilePics/" + filename);
        $("#alert").css("display", "inherit");
    });
</script>
